#include // Pin Pulsanti (Esempio per Motore A e B, estendibile a C e D) const int buttonA_CW = A0; // Orario const int buttonA_CCW = A1; // Antiorario const int buttonB_CW = A2; const int buttonB_CCW = A3; const int buttonC_CW = A4; const int buttonC_CCW = A5; const int buttonD_CW = A6; const int buttonD_CCW = A7; // Pin Driver (Step, Dir) AccelStepper stepperA(1, 2, 3); AccelStepper stepperB(1, 4, 5); AccelStepper stepperC(1, 6, 7); AccelStepper stepperD(1, 8, 9); unsigned long ultimoControllo = 0; const long intervalloSeriale = 1000; // 2 secondi void setup() { Serial.begin(9600); // Configurazione pulsanti con Pullup interno pinMode(buttonA_CW, INPUT_PULLUP); pinMode(buttonA_CCW, INPUT_PULLUP); pinMode(buttonB_CW, INPUT_PULLUP); pinMode(buttonB_CCW, INPUT_PULLUP); pinMode(buttonC_CW, INPUT_PULLUP); pinMode(buttonC_CCW, INPUT_PULLUP); pinMode(buttonD_CW, INPUT_PULLUP); pinMode(buttonD_CCW, INPUT_PULLUP); // Velocità massima per il movimento continuo stepperA.setMaxSpeed(1000); stepperB.setMaxSpeed(1000); stepperC.setMaxSpeed(1000); stepperD.setMaxSpeed(1000); } void loop() { // --- LOGICA DI MOVIMENTO (NON BLOCCANTE) --- // Gestione Motore A if (digitalRead(buttonA_CW) == LOW) { stepperA.setSpeed(400); // Velocità positiva stepperA.runSpeed(); } else if (digitalRead(buttonA_CCW) == LOW) { stepperA.setSpeed(-400); // Velocità negativa stepperA.runSpeed(); } else { stepperA.setSpeed(0); // Fermo } // Gestione Motore B if (digitalRead(buttonB_CW) == LOW) { stepperB.setSpeed(400); stepperB.runSpeed(); } else if (digitalRead(buttonB_CCW) == LOW) { stepperB.setSpeed(-400); stepperB.runSpeed(); } else { stepperB.setSpeed(0); } // --- STAMPA STATO OGNI 2 SECONDI (NON BLOCCANTE) --- unsigned long tempoAttuale = millis(); if (tempoAttuale - ultimoControllo >= intervalloSeriale) { ultimoControllo = tempoAttuale; Serial.println("--- Stato Pulsanti ---"); Serial.print("Motore A: "); Serial.print(digitalRead(buttonA_CW) == LOW ? "CW " : "- "); Serial.println(digitalRead(buttonA_CCW) == LOW ? "CCW" : "-"); Serial.print("Motore B: "); Serial.print(digitalRead(buttonB_CW) == LOW ? "CW " : "- "); Serial.println(digitalRead(buttonB_CCW) == LOW ? "CCW" : "-"); Serial.print("Motore C: "); Serial.print(digitalRead(buttonC_CW) == LOW ? "CW " : "- "); Serial.println(digitalRead(buttonC_CCW) == LOW ? "CCW" : "-"); Serial.print("Motore D: "); Serial.print(digitalRead(buttonD_CW) == LOW ? "CW " : "- "); Serial.println(digitalRead(buttonD_CCW) == LOW ? "CCW" : "-"); } }